<template>
  <div>
    <!-- 导航 -->
    <van-nav-bar title="频道管理">
      <template #right>
        <van-icon
          name="cross"
          size="0.37333334rem"
          color="white"
          @click="closeFn"
        />
      </template>
    </van-nav-bar>

    <!-- 我的频道 -->
    <div class="my-channel-box">
      <div class="channel-title">
        <span>
          我的频道
          <span class="small-title">
            点击 {{ isEdit ? "删除" : "进入" }} 频道
          </span>
        </span>
        <span @click="onClickedit">{{ isEdit ? "完成" : "编辑" }}</span>
      </div>
      <!-- 我的频道列表 -->
      <van-row type="flex">
        <van-col
          span="6"
          v-for="obj in userList"
          :key="obj.id"
          @click="userChannelClickFn(obj)"
        >
          <div class="channel-item van-hairline--surround">
            {{ obj.name }}
            <!-- 删除的徽标 -->
            <van-badge
              color="transparent"
              class="cross-badge"
              v-show="isEdit && obj.id !== 0"
            >
              <template #content>
                <van-icon
                  name="cross"
                  class="badge-icon"
                  size="0.32rem"
                  color="#cfcfcf"
                />
              </template>
            </van-badge>
          </div>
        </van-col>
      </van-row>
    </div>

    <!-- 更多频道 -->
    <div class="more-channel-box">
      <div class="channel-title">
        <span>点击添加更多频道</span>
      </div>
      <!-- 更多频道列表 -->
      <van-row type="flex">
        <van-col
          span="6"
          v-for="obj in unCheckList"
          :key="obj.id"
          @click="moreFn(obj)"
        >
          <div class="channel-item van-hairline--surround">{{ obj.name }}</div>
        </van-col>
      </van-row>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    userList: Array, //用户已选择
    unCheckList: Array, //未选择
  },
  data() {
    return {
      isEdit: false, //编辑状态(x隐藏)
    };
  },
  methods: {
    //   编辑->点击事件
    onClickedit() {
      this.isEdit = !this.isEdit;
    },

    // 关闭弹窗层
    closeFn() {
      this.$emit("closeEV");
      // this.isEdit = false;//第一种:弹窗层初始化
    },

    //更多频道->点击事件
    moreFn(channelObj) {
      if (this.isEdit === true) {
        //处于编辑状态
        // this.userList.push(channelObj)
        this.$emit("addChannelEV", channelObj);
      }
    },

    // 用户频道选择-点击事件
    userChannelClickFn(channelObj) {
      //处于编辑状态 -> 执行删除功能
      if (this.isEdit === true) {
        if (channelObj.id !== 0) {
          this.$emit("removeChannelEV", channelObj);
        }
      } else {
        //切换频道
        this.$emit("closeEV"); //关闭弹出层
        this.$emit("input", channelObj.id); //触发v-model绑定的input事件 //把值传出去绑定给v-model对应vue变量
      }
    },
  },
};
</script>

<style lang="less" scoped>
.van-nav-bar {
  background: #1989fa;

  /deep/.van-nav-bar__title {
    color: #fff;
  }
  /deep/.van-nav-bar__text {
    color: #fff;
  }
  .imglogo {
    width: 45px;
    height: 46px;
  }
}

.van-popup,
.popup-container {
  background: transparent;
  height: 100%;
  width: 100%;
}
.popup-container {
  display: flex;
  flex-direction: column;
}

.pop-header {
  height: 90px;
  background: #007bff;
  color: white;
  text-align: center;
  font-size: 14px;
  position: relative;
  .title {
    width: 100%;
    position: absolute;
    bottom: 15px;
  }
}

.pop-body {
  flex: 1;
  overflow: scroll;
  padding: 8px;
}

.my-channel-box,
.more-channel-box {
  .channel-item {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    line-height: 28px;
    padding: 0 6px;
  }
}

.van-hairline--surround {
  background: #fafafa;
  margin: 5px;
}

.channel-title {
  font-size: 12px;
  text-align: center;
  line-height: 36px;
  margin: 5px;
  display: flex;
  justify-content: space-between;
}

.cross-badge {
  position: absolute;
  right: -3px;
  top: 0;
  border: none;
}

.small-title {
  font-size: 10px;
  color: gray;
}
</style>